package com.chinadci.smartcommunitysystembackstage.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinadci.smartcommunitysystembackstage.entity.ScsForum;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chinadci.smartcommunitysystembackstage.mapper.ScsAdmintypeMapper;
import com.chinadci.smartcommunitysystembackstage.mapper.ScsForumMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author Code Duck
 * @since 2021-04-13
 */
@Service
public class ScsForumService{
    @Autowired
    private ScsForumMapper mapper;

    private Logger log= LoggerFactory.getLogger(this.getClass());

    //显示所有朋友圈
    public List<ScsForum> Find(){
        log.info("=====显示所有朋友圈");
        List<ScsForum> list=mapper.Find();
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setName(list.get(i).getUser().get(0).getUName());
        }
        return list;
    }

    //根据用户名查找朋友圈
    public List<ScsForum> Finds(int id){
        log.info("=====根据用户名查找朋友圈");
        List<ScsForum> list=mapper.Finds(id);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setName(list.get(i).getUser().get(0).getUName());
        }
        return list;
    }


    //删除朋友圈
    public int Del(int id){
        log.info("=====删除指定朋友圈");
        QueryWrapper<ScsForum> qw=new QueryWrapper<>();
        qw.eq("f_id",id);
        return mapper.delete(qw);
    }
}
